const remote = require('electron').remote;
const dialog = remote.dialog;
function onClick_OpenFile () {
    const label = document.getElementById('label');
    label.innerText = dialog.showOpenDialog({properties:['OpenFile']})
}
//定制打开对话框
function onClick_CustomOpenFile() {
    const label = document.getElementById('label');
    var options = {};
    options.title = '打开文件夹';
    options.buttonLabel = '选择';
    options.defaultPath = '/image'
    options.properties = ['OpenFile'];
    label.innerText = dialog.showOpenDialog(options);
}
//选择文件类型
function onClick_FileType() {
    const label = document.getElementById('label');
    var options = {};
    options.title = '选择文件类型';
    options.buttonLabel = '选择';
    options.properties = ['OpenFile'];
    options.filters = [
        {name:'图像文件',extensions:['jpg','bmp','png','gif']},
        {name:'视频文件',extensions:['mkv','avi','mp4']},
        {name:'音频文件',extensions:['mp3','wav']},
        {name:'所有文件(*.*)',extensions:['*']}
    ];
    label.innerText = dialog.showOpenDialog(options);
}
//选择目录
function onClick_Directory() {
    const label = document.getElementById('label');
    var options = {};
    options.title = '选择目录';
    options.buttonLabel = '选择';
    options.properties = ['OpenDirectory'];
    label.innerText = dialog.showOpenDialog(options);
}
//多选文件和目录
function onClick_MultiSelection() {
    const label = document.getElementById('label');
    var options = {};
    options.title = '选择目录';
    options.buttonLabel = '选择';
    options.properties = ['openFile','multiSelections'];
    label.innerText = dialog.showOpenDialog(options);
}
//通过回调函数返回选择结果
function onClick_Callback() {
    const label = document.getElementById('label');
    var options = {};
    options.title = '选择目录';
    options.buttonLabel = '选择';
    options.properties = ['openFile','multiSelections'];
    label.innerText = dialog.showOpenDialog(options,(filePaths) => {
        for(var i =0; i < filePaths.length; i++) {
            label.innerText += filePaths[i] + '\r\n';
        }
    });
}